package com.example.demo.mapper;

import java.util.List;
import java.util.Set;

import com.example.demo.bean.ResultExportVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import com.example.demo.bean.Orders;
import com.example.demo.bean.OrdersVo;
import com.example.demo.requestentity.OrdersInsertRecords;
import com.example.demo.requestentity.OrdersUpdateRecords;
import com.example.demo.responseentity.OrdersResponseEntity;
@Repository
public interface OrdersMapper {
    int deleteByPrimaryKey(String id);

    int insert(Orders record);

    int insertSelective(Orders record);

    Orders selectByPrimaryKey(String id);

    int updateSelective(Orders record);

    int updateByPrimaryKey(Orders record);

    OrdersResponseEntity queryByname(String name);

    int delete(String name);

    String getIdByName(String name);


    /**
    * 批量插入
    * @param list
    * @param date
    * @return
    * @author kongjiawei
    * @date 2021/9/5 16:26
    */
    int insertBatch(@Param("list") List<OrdersInsertRecords> list, @Param("date") String date);


    /**
     * 通过饮料名查询饮料Id
     * @param list
     * @return
     * @author kongjiawei
     * @date 2021/9/5 16:27
     */
    List<String> queryByDrinkNames(@Param("list") List<String> list);


    /**
     * 批量删除
     * @param list
     * @return
     * @author kongjiawei
     * @date 2021/9/5 16:25
     */
    int removeBatch(@Param("list")List<String> list);

    /**
     * 查询所有用户的
     * @param s
     * @return
     * @author kongjiawei
     * @date 2021/9/5 16:42
     */
    @Select("SELECT  o.u_name AS name, o.work_place AS workplace , d.drinkname FROM orders o LEFT JOIN drink d ON o.d_id = d.id WHERE o.u_name LIKE #{name}")
    List<OrdersVo> query(@Param(value = "name") String s);

    @Select("SELECT count(id) from orders")
    Integer queryPeopleCount();

    @Select("SELECT\n" +
            "\tdrinkname,\n" +
            "\tcount( drinkname ) AS count,\n" +
            "\twork_place \n" +
            "FROM\n" +
            "\torders o\n" +
            "\tLEFT JOIN drink d ON o.d_id = d.id \n" +
            "GROUP BY\n" +
            "\twork_place,\n" +
            "\td.drinkname \n" +
            "\tORDER BY\n" +
            "\twork_place\n" +
            "\tDESC")
    List<ResultExportVO> export();

    /**
    * 批量更新
    * @param list
    * @param date
    * @return
    * @author kongjiawei
    * @date 2021/9/5 16:27
    */
    int updateBatch(@Param("list") List<OrdersUpdateRecords> list,@Param("date") String date);

    /**
     * 查询所有用户名
     * @param
     * @return
     * @author kongjiawei
     * @date 2021/9/7 11:44
     */
    @Select("select u_name from orders")
    Set<String> queryUnames();

}
